﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using Register.BLL;
using Register.Model;
using System.Web.Script.Serialization;

namespace RegisterWeb.Manager.PatientManager.ashx
{
    /// <summary>
    /// PayforPatientService 的摘要说明
    /// </summary>
    public class PayforPatientService : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request["action"];

            if (action == "1")
            {           
                List<Parameter> parameter;
                parameter = ParamterHelper.GetParametersByType("Patient_UserLevel");
                String[,] Name = new String[5, 2];
                int length = 0;
                foreach (Parameter a in parameter)
                {
                    Name[length, 0] = a.SystemParameter_Name;
                    Name[length, 1] = "PatientUserInfo_UserType='" + a.SystemParameter_ID + "'  ";
                    length++;
                }

                String[] strdata = GetPatientTypeNum(Name,length);
                List<data> list = new List<data>();
                for (int i = 0; i < length; i++)
                {
                    data dt = new data();
                    dt.ydata = strdata[i];
                    dt.xdata = Name[i, 0];
                    list.Add(dt);
                }
                JavaScriptSerializer jss = new JavaScriptSerializer();
                string ss = jss.Serialize(list);
                context.Response.Write(ss);
            }
            if (action == "2")
            {
                String[,] Name = { { "全到", "PatientUserInfo_NotComeTime = 0" }, { "1次未到", "PatientUserInfo_NotComeTime = 1" }, { "2次未到", "PatientUserInfo_NotComeTime = 2" }, { "超过3次未到", "PatientUserInfo_NotComeTime > 3" } };
                int length = 4;

                String[] strdata = GetPatientTypeNum(Name, length);
                List<data> list = new List<data>();
                for (int i = 0; i < length; i++)
                {
                    data dt = new data();
                    dt.ydata = strdata[i];
                    dt.xdata = Name[i, 0];
                    list.Add(dt);
                }
                JavaScriptSerializer jss = new JavaScriptSerializer();
                string ss = jss.Serialize(list);
                context.Response.Write(ss);
            }
        }
        /// <summary>
        /// 获得数量
        /// </summary>
        /// <param name="Name">名称和条件查询</param>
        /// <param name="length">长度</param>
        /// <returns>数量</returns>
        public static String[] GetPatientTypeNum(String[,] Name, int length)
        {
            String[] dt1;
            dt1 = new String[5];
            for (int i = 0; i < length; i++)
            {
                dt1[i] = PatientUserInfoBLL.GetPatientUserInfoCount(Name[i, 1]).ToString();
            }
            return dt1;
        }


        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public class data
        {
            public  String xdata { get; set; }
            public String  ydata { get; set; }
        }



    }
}